/*
 * @Author: xiaosihan 
 * @Date: 2023-11-30 23:27:10 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2023-12-07 00:14:37
 */



import { DesignTemplateDate, RepeatType } from "#/type";
import { debounce } from "lodash";
import { configure, observable } from "mobx";

configure({ enforceActions: "never" });

const designTemplateEditorStore = observable({

    //显示编辑弹窗
    open: false,
    // 设计模板数据
    design_template: {} as DesignTemplateDate,

    // 设置设计模版
    set_design_template(design_template: DesignTemplateDate) {
        this.open = true;
        this.design_template = design_template;
    },

    //关闭
    close() {
        this.open = false;
        this.saveIng = false;
    },


    // 当前选中的部位
    activeComponent: "",
    setActiveComponent(activeComponent: string) {
        if (this.activeComponent !== activeComponent) {
            this.activeComponent = activeComponent;
        }
    },

    //保存中
    saveIng: false,
    setSaveIng(saveIng: boolean) {
        this.saveIng = saveIng;
    },

    //图层的ids
    layerIds: "" as string,
    setLayerIds: debounce((layerIds: string) => {
        designTemplateEditorStore.layerIds = layerIds;
    }, 50),

    // 编辑器的缩放
    scale: 40,
    setScale(scale: number) {
        this.scale = scale;
    },

    //最大缩放
    maxScale: 50,
    setMaxScale(maxScale: number) {
        const s = maxScale / this.maxScale;
        this.maxScale = maxScale;
        this.scale = Math.min(this.scale * s, maxScale);
    },

    //当前选中对象的id
    activeObjectId: "",
    setActiveObjectId(activeObjectId: string) {
        this.activeObjectId = activeObjectId;
    },

    // 对象旋转状态
    rotation: 0,
    setRotation(rotation: number) {
        this.rotation = rotation;
    },

    //对象的平铺类型
    repeat: "no_repeat" as RepeatType,
    setRepeat(repeat: RepeatType) {
        this.repeat = repeat;
    },

    // 显示重复间距控制器
    showRepeatSpaceContorl: false,
    setShowRepeatSpaceContorl(showRepeatSpaceContorl: boolean) {
        this.showRepeatSpaceContorl = showRepeatSpaceContorl;
    },

    // 间距关联
    repeatSpacelink: true,
    setRepeatSpacelink(repeatSpacelink: boolean) {
        this.repeatSpacelink = repeatSpacelink;
        if (this.repeatSpacelink) {
            this.repeatSpaceY = this.repeatSpaceX;
        }
    },

    // 平铺的横向间距
    repeatSpaceX: 0,
    setRepeatSpaceX(repeatSpaceX: number) {
        this.repeatSpaceX = repeatSpaceX;
    },

    // 平铺的纵向间距
    repeatSpaceY: 0,
    setRepeatSpaceY(repeatSpaceY: number) {
        this.repeatSpaceY = repeatSpaceY;
    },

    // 设置当前选中文字的字体
    fontFamily: "",
    setFontFamily(fontFamily: string = "") {
        this.fontFamily = fontFamily;
    },

    // 设置当前选中文字的大小
    fontSize: 20,
    setFontSize(fontSize: number) {
        this.fontSize = fontSize;
    },

    // 设置字体间距
    fontSpace: 0,
    setFontSpace(fontSpace: number) {
        this.fontSpace = fontSpace;
    },

    //设置锁定状态
    lock: false,
    setLock(lock: boolean) {
        this.lock = lock;
    },

    //颜色拾取中
    colorPicker: false,
    originColor: "#ffffff",
    pickerColor: "#ffffff",// 吸色工具拾取到的颜色
    setColorPicker(colorPicker: boolean, originColor = "#ffffff") { // 开启颜色拾取
        this.originColor = originColor;
        this.colorPicker = colorPicker;
    },
    setPickerColor(color: string) {
        this.pickerColor = color;
    }



});

export default designTemplateEditorStore;